package nioTest;

import java.io.RandomAccessFile;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;

/**
 * 名称: ReadTextByNIO.java <br>
 * 描述: <br>
 * 最近修改时间:2018/5/4 16:14 <br>
 *
 * @version [版本号, V1.0]
 * @since 2018/5/4 16:14
 * @author zhipingzhang  
 */
public class WriteTextByNIO {

    public static void main(String[] args) throws Exception {
        RandomAccessFile aFile = new RandomAccessFile("C:\\Users\\zhipingzhang\\Desktop\\worklist\\20180410多租户改造二期\\生产配置\\" +
                "20180420-P-084046\\prd-config\\admin-server\\test.properties", "rw");

        FileChannel outChannel = aFile.getChannel();

        String newData = "New String to write to file..." + System.currentTimeMillis();
        ByteBuffer buf = ByteBuffer.allocate(48);
        buf.clear();
        buf.put(newData.getBytes());
        buf.flip();
        while(buf.hasRemaining()) {
            outChannel.write(buf);

        }
        outChannel.close();
        aFile.close();
    }
}
